//
//  DAFileSearchTableViewCell.m
//  DAKnowledge
//
//  Created by 黄健宇 on 16/7/28.
//  Copyright © 2016年 lidongyang. All rights reserved.
//

#import "DAFileSearchTableViewCell.h"
#import "DAUserFileSearchModel.h"
#import "Utility.h"
#import "DAHeader.h"

@implementation DAFileSearchTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
    self.progress.tintColor = [UIColor supportGreenColor];
}

- (void)setUserFileSearchModel:(DAUserFileSearchModel *)userFileModel{
    NSString *file = [NSString stringWithFormat:@"file_%@.png",userFileModel.fileExtend];
    UIImage *image = [UIImage imageNamed:file];
    self.fileNameLabel.text = userFileModel.fileName;
    self.fileImageView.image = image;
    self.fileIntroduction.text = userFileModel.fileType;
    self.fileIntroduction.textColor = [UIColor colorWithHexString:timeColor];
    //进度条处理
    if(userFileModel.isDownloading == NO){
        self.progress.hidden = YES;
        self.progress.progress = 0;
    }else{
        self.progress.hidden = NO;
    }
    
    // 下载完成之后   显示已下载的图表
    if (userFileModel.isDownloadingSuccessful == YES) {
        self.downLoadCompleteImage.image = [UIImage imageNamed:@"complete@3x"];
    }else{
        self.downLoadCompleteImage.image = nil;
    }
    
    //处理文件大小
    int fileSize = [userFileModel.fileSize intValue];
    float fileSizeM = 0.0;
    float fileSizeK = 0.0;
    if (fileSize >999 && fileSize < 999*1024) {
        fileSizeK = fileSize/1024.0;
        self.fileSize.text = [NSString stringWithFormat:@"%.2fK",fileSizeK];
    }else if(fileSize >= 999*1024){
        fileSizeM = fileSize/(1024.0*1024.0);
        self.fileSize.text = [NSString stringWithFormat:@"%.2fM",fileSizeM];
    }else{
        self.fileSize.text = [NSString stringWithFormat:@"%dK",fileSize];
    }
    
    self.fileSize.textColor = [UIColor colorWithHexString:timeColor];

}
#pragma mark - 判断沙盒里是否有这个文件
-(BOOL)isFileExist:(NSString *)fileName inPath:(NSString *)path{
    NSString *filePath = [path stringByAppendingPathComponent:fileName];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL result = [fileManager fileExistsAtPath:filePath];
    //  NSLog(@"该文件：%@",result?@"有！！":@"不存在");
    return result;
}

@end
